/**
 * 通用模块
 *
 */
var $win = $(window),
    $doc = $(document),
    $body = $('body', $doc),
    winW = $win.width();

$(window).resize(function() {
    winW = $win.width();
})


/**
 * 图片加载
 */
$(function() {
    if (!$.fn.lazyload) return;
    $("img.lazy", $body).lazyload({
        effect: "fadeIn",
        threshold: 200,
        failure_limit: 0
    });
});


$(function() {
    if ($win.width() > 992) {
        if (!(/msie [6|7|8|9]/i.test(navigator.userAgent))) {
            new WOW().init();
        };
    }

});

// window.onload = function(){
//     alert(1)
//     $("#cha").contents().find("h1").css('color','red');
//     console.log($("#cha").contents().find('body .tvp_poster_img'));
// }





// 语言版本下拉
$(function() {
    var $nav_li = $(".header .lang");
    $nav_li.hover(function() {
        $(this).find('ul').stop(true, true).slideDown(200);
    }, function() {
        $(this).find('ul').slideUp(200);
    });
});


$(function() {
    $(window).on("scroll", function() {
        var t = document.documentElement.scrollTop || document.body.scrollTop;
        if (screen.width > 0) {
            if (t >= 100) { //鍒ゆ柇
                $(".header").addClass("fixed-header");
            } else {
                $(".header").removeClass("fixed-header");
            }
        }
    })
});



// 视频
$(function() {
    var $box = $(".video", $body);
    if (!$box.length) return;

    $box.on('click', '.video-box .play', function(event) {
        event.preventDefault();
        var me = $(this);

        var $iframe = me.next('.iframe'),
            url = $iframe.data('src');

        if ($win.width() > 1200) {
            $.fancybox.open([url], {
                type: 'iframe',
                padding: 10,
            });
        } else {
            var height = me.find('.img-responsive').length ? me.height() : $box.height();
            height = Math.max(height, 170);
            if (!$iframe.attr('src')) $iframe.attr('src', url);
            $iframe.height(height);
            $iframe.css('display', 'block');
            me.hide();
        }
    });
});


//头部导航
$(function() {
    //折叠导航
    var oset;
    $(".nav-collapse").click(function(e) {
        if (e && e.stopPropagation) {
            e.stopPropagation();
        } else {
            window.event.cancelBubble = true;
        }
        $(".nav-collapse").toggleClass("active");

        $(".nav").stop().fadeToggle().toggleClass("fade-out");
        $("body").toggleClass("fixed");
        $(".nav").removeClass("left-100 left-200");

        if (!$(this).hasClass("active")) {
            $(".nav").hide();
            $(".nav-list1").find("li").removeClass("act");
        } else {
            clearTimeout(oset);
            $(".nav-list1>li").each(function(index, val) {
                var me = $(this);
                var num = $(this).index()
                oset = setTimeout(function() {
                    me.addClass("act");
                }, (index * 100))
            })
        }
    })

});

$(function() {

    var list1 = $(".nav-list1"),
        list2 = $(".nav-list2"),
        list3 = $(".nav-list3");
    list1.on("click", ".more", function(event) {
        if (winW > 1199) return;
        event.stopPropagation();
        event.preventDefault();
        $(".nav").addClass("left-100");
        var ostr = "";
        ostr = $(this).children(".nav-list2").html();
        ohref = $(this).children("a").clone(true);
        $(".nav-2 .content ul").html(ostr).children("li").has(".nav-list3").addClass("more");
        $(".nav-2 h2").html(ohref);

    })
    $(".nav2-list2").on("click", "li", function(event) {
        if (winW > 1199) return;
        event.stopPropagation();
        if ($(this).hasClass("more")) {
            event.preventDefault();
            $(".nav").addClass("left-200");
            var ostr = "";
            ostr = $(this).children(".nav-list3").html();
            ohref = $(this).children("h4").children("a").clone(true);
            console.log($(this).children("h4 a"));
            $(".nav-3 .content ul").html(ostr);
            $(".nav-3 h2").html(ohref);
        }
    })

    list1.on("mouseenter", ".more", function(event) {

        if (winW < 1200) return;
        var me2 = $(this).children(".nav-list2");
        me2
            .stop().slideDown("fast")
            .children("li").has(".nav-list3").addClass("more");

    }).on("mouseleave", ".more", function(event) {

        if (winW < 1200) return;
        $(this).children(".nav-list2").stop().slideUp("fast");

    })

    list2.on("mouseenter", "li", function(event) {
        if (winW < 1200) return;
        console.log($(this).children(".nav-list3"))
        // $(this).children(".nav-list3").stop().slideDown("fast");
    }).on("mouseleave", "li", function(event) {
        if (winW < 1200) return;
        // $(this).children(".nav-list3").stop().slideUp("fast");
    })

    $(".back-btn2").click(function() {
        $(".nav").removeClass("left-100");
    })
    $(".back-btn3").click(function() {
        $(".nav").removeClass("left-200");
    })
    //查找按钮
    $(".find").click(function(e) {
        if (e && e.stopPropagation) {
            //W3C取消冒泡事件
            e.stopPropagation();
        } else {
            //IE取消冒泡事件
            window.event.cancelBubble = true;
        }
        $(".search-lg").stop().fadeIn();
        $(".input-text").focus();
        $("body").addClass('searchactive');
        if (winW < 1200) {
            $("#btn").removeClass("active");
        }
    })

    $(".search-icon").click(function() {
        if (winW < 1200) {
            $(".search-xs").addClass("show")
        }
    })
    $(".nav").click(function(e) {
        if (!$(e.target).hasClass("input-text") && !$(e.target).hasClass("search-icon")) {
            console.log(e.target);
            $(".search-xs").removeClass("show")
        }
    })

    $(".close-btn").click(function() {
        $(".search-lg").fadeOut("fast");
        $("body").removeClass('searchactive');
    })


});



/**
 * 幻灯切换
 */
$(function() {
    if (!$.fn.owlCarousel) return;

    // 首页 banner
    $('#owl-index').owlCarousel({
        autoPlay: 4000,
        autoPlay: true,
        autoHeight: false,

        stopOnHover: false,
        lazyLoad: true,

        singleItem: true,
        slideSpeed: 300,
        autoPlay: true,
        navigation: true,
        navigationText: false,
        paginationSpeed: 400,
        transitionStyle: "fade",
        afterAction: function() {
            var current = this.currentItem;
            console.log(current);
            $(".owl-item")
                .eq(current)
                .addClass("active")
                .siblings().removeClass("active");
        }
    });
});

$(function() {
    if (!$.fn.owlCarousel) return;

    $('#owl-honor').owlCarousel({
        autoPlay: 4000,
        autoPlay: true,
        autoHeight: false,

        stopOnHover: false,
        lazyLoad: true,

        singleItem: true,
        slideSpeed: 300,
        autoPlay: true,
        navigation: true,
        navigationText: false,
        paginationSpeed: 400,
        transitionStyle: "fade",
    });
});


$(function() {
    if (!$.fn.owlCarousel) return;

    $('#owl-solution').owlCarousel({
        autoPlay: 4000,
        autoPlay: true,
        autoHeight: false,

        stopOnHover: false,
        lazyLoad: true,

        singleItem: true,
        slideSpeed: 300,
        autoPlay: true,
        navigation: true,
        navigationText: false,
        paginationSpeed: 400,
        transitionStyle: "fade",
    });
});

$(function() {
    if (!$.fn.owlCarousel) return;

    $('#owl-service').owlCarousel({
        autoPlay: 4000,
        autoPlay: true,
        autoHeight: false,

        stopOnHover: false,
        lazyLoad: true,

        singleItem: true,
        slideSpeed: 300,
        autoPlay: true,
        navigation: true,
        navigationText: false,
        paginationSpeed: 400,
        transitionStyle: "fade",
    });
});


// 产品
$('#owl-product').owlCarousel({
    navigation: true,
    navigationText: false,

    pagination: true,
    paginationSpeed: 400,

    slideSpeed: 400,
    singleItem: false,

    items: 4,
    itemsDesktopSmall: [1199, 3],
    itemsTablet: [768, 2],
    itemsTabletSmall: [480, 2],
    itemsMobile: [320, 1],

    autoPlay: 2000,
    lazyLoad: true,

    autoHeight: false,
    stopOnHover: false,


    // afterInit: function() {
    //     if ($body.width() < 768) this.stop();
    // }
});


$(document).ready(function() {

    var sync1 = $("#sync1");
    var sync2 = $("#sync2");

    sync1.owlCarousel({
        autoPlay: true,
        lazyLoad: true,

        singleItem: true,
        slideSpeed: 1000,
        navigation: true,
        pagination: false,
        afterAction: syncPosition,
        responsiveRefreshRate: 200,
    });

    sync2.owlCarousel({
        autoPlay: true,
        lazyLoad: true,
        items: 5,
        itemsDesktop: [1200, 5],
        itemsDesktopSmall: [991, 5],
        itemsTablet: [767, 4],
        itemsMobile: [480, 4],
        pagination: false,
        responsiveRefreshRate: 100,
        afterInit: function(el) {
            el.find(".owl-item").eq(0).addClass("synced");
        }
    });

    function syncPosition(el) {
        var current = this.currentItem;
        sync2
            .find(".owl-item")
            .removeClass("synced")
            .eq(current)
            .addClass("synced")
        if (sync2.data("owlCarousel") !== undefined) {
            center(current)
        }

        sync2
            .find(".owl-item")
            .removeClass("synced")
            .eq(current)
            .addClass('class_name')
    }

    sync2.on('mouseover', '.owl-item', function(e) {
        e.preventDefault();
        var number = $(this).data("owlItem");
        sync1.trigger("owl.goTo", number);
    });

    function center(number) {
        var sync2visible = sync2.data("owlCarousel").owl.visibleItems;

        var num = number;
        var found = false;
        for (var i in sync2visible) {
            if (num === sync2visible[i]) {
                var found = true;
            }
        }

        if (found === false) {
            if (num > sync2visible[sync2visible.length - 1]) {
                sync2.trigger("owl.goTo", num - sync2visible.length + 2)
            } else {
                if (num - 1 === -1) {
                    num = 0;
                }
                sync2.trigger("owl.goTo", num);
            }
        } else if (num === sync2visible[sync2visible.length - 1]) {
            sync2.trigger("owl.goTo", sync2visible[1])
        } else if (num === sync2visible[0]) {
            sync2.trigger("owl.goTo", num - 1)
        }
    }

});


// 浮动客服弹出二维码and缓冲回到顶部

$(function() {
    $('.online > .online-wechat').hover(function() {
        $('.online-wechat .erweima').stop(true, true).fadeIn();
    }, function() {
        $('.online-wechat .erweima').stop(true, true).fadeOut();
    });
    $('.online > .online-weixin').hover(function() {
        $('.online-weixin .erweima').stop(true, true).fadeIn();
    }, function() {
        $('.online-weixin .erweima').stop(true, true).fadeOut();
    });
    $('.online > .online-tel').hover(function() {
        $('.online-tel p').stop(true, true).fadeIn();
    }, function() {
        $('.online-tel p').stop(true, true).fadeOut();
    });
    $('.online > .online-whatsapp').hover(function() {
        $('.online-whatsapp p').stop(true, true).fadeIn();
    }, function() {
        $('.online-whatsapp p').stop(true, true).fadeOut();
    });
    $('#backtop,.backtop').click(function() {
        $("html, body").animate({
            scrollTop: 0
        }, 400);
    });
});



$(function() {
    $('.icon-online').click(function() {
        $('.online').toggleClass('active');
        $('.icon-online').toggleClass('icon');
    });
});

 $(".pro-show a.inquiry").click(function() {

    $("html,body").animate({
        scrollTop: $('.inquire').offset().top - 80
    }, 400)

})


// 产品详情tab选项卡
$(function() {
    $('.parameter .category li').click(function() {
        var liindex = $('.parameter .category li').index(this);
        $(this).addClass('active').siblings().removeClass('active');
        $('.parameter .note').eq(liindex).show().siblings('.note').hide();
    }).eq(0).click();
});

$(".product-show .link a").click(function() {
    $(".inquiry")
        .addClass("active")
        .siblings().removeClass("active");

    $(".tab-note").children(".note").eq($('.parameter .category li').children(".active").index())
        .show()
        .siblings().hide("fast");

    $("html,body").animate({
        scrollTop: $('.parameter .category li').offset().top - 150
    }, 400)

})


$(".wrap-faq .faq ul li .note-1").click(function() {
    var par = $(this).parent();
    if (par.attr("class") == "on") {
        $(".wrap-faq .faq ul li .note-1").parent().addClass("on").children('.note-2').slideUp();
        par.children('.note-2').slideDown();
        par.removeClass("on").addClass("current").siblings().removeClass('current');
    } else {
        par.children('.note-2').slideUp();
        par.addClass("on").removeClass("current");
    }

});
// 表格
$(function() {
    var oTable = $("table");
    if (oTable.length !== 0) {
        var oTr = oTable.find('tr'),
            oTd = oTable.find('td');

        oTable.wrap("<div class='table-box'></div>");

        oTr.attr("style", "");

        oTd.each(function(index) {
            if (typeof($(this).attr("style")) !== "undefined") {

                if ($(this).attr("style").indexOf("text-align: center") >= 0) {
                    $(this).attr("style", "text-align: center");
                } else {
                    $(this).attr("style", "");
                }

            }
        })

    }
});

$(function() {
    if (!placeholderSupport()) { // 判断浏览器是否支持 placeholder
        $('[placeholder]').focus(function() {
            var input = $(this);
            if (input.val() == input.attr('placeholder')) {
                input.val('');
                input.removeClass('placeholder');
            }
        }).blur(function() {
            var input = $(this);
            if (input.val() == '' || input.val() == input.attr('placeholder')) {
                input.addClass('placeholder');
                input.val(input.attr('placeholder'));
            }
        }).blur();
    };
})

function placeholderSupport() {
    return 'placeholder' in document.createElement('input');
}



if (winW > 767) {
    $(".box-system .info .list").each(function(index, el) {

        var max = 0;
        $(this).children(".item").children(".pic").each(function() {
            max = Math.max($(this).height(), max);
        })
        $(this).children(".item").children(".text").height(max);

    })
}
